import { ADDPATH, DELETEPATH,RESOVE } from "../constant"


const initPre = [{
    path: "/home/Page",
    label: "首页",
    keyPath: ['1'],
    key: '1'
}]

interface action {
    type: String,
    data: any
}

export default function countReducer(preState = initPre, action: action) {
    const { type, data } = action
    switch (type) {
        case ADDPATH:
            let path = preState.find((item: any) => item.key == data.key)
            if (path) {
                return preState
            } else {
                let MixData = [...preState, data]
                return MixData
            }
        case DELETEPATH:
            return preState.filter((item: any) => item.key != data.key)
        case RESOVE:
            console.log(preState);
            return [{
                path: "/home/Page",
                label: "首页",
                keyPath: ['1'],
                key: '1'
            }]
        default:
            return preState
    }
}
